home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 17 / CU Amiga Magazine's Super CD-ROM 17 (1997)(EMAP Images)(GB)[!][issue 1997-12].iso / CUCD / Programming / DiceSource / lib / amiga / path.c < prev    next >
C/C++ Source or Header  |  1997-09-09  |  1KB  |  62 lines

  1.  
  2. /*
  3.  *  PATH.C
  4.  *
  5.  *    (c)Copyright 1992-1997 Obvious Implementations Corp.  Redistribution and
  6.  *    use is allowed under the terms of the DICE-LICENSE FILE,
  7.  *    DICE-LICENSE.TXT.
  8.  *
  9.  *  Search the path for a command name
  10.  */
  11.  
  12. #include <exec/types.h>
  13. #include <exec/execbase.h>
  14. #include <libraries/dos.h>
  15. #include <libraries/dosextens.h>
  16. #include <clib/dos_protos.h>
  17. #include <stdio.h>
  18. #include <lib/bcpl.h>
  19. #include <lib/misc.h>
  20.  
  21. typedef struct CommandLineInterface CLI;
  22. typedef struct Process Process;
  23.  
  24. typedef struct LockList {
  25.     BPTR    NextPath;
  26.     BPTR    PathLock;
  27. } LockList;
  28.  
  29. extern struct ExecBase *SysBase;
  30.  
  31. long
  32. _SearchPath(cmd)
  33. char *cmd;
  34. {
  35.     CLI *cli;
  36.     LockList *ll;
  37.  
  38.     if (SysBase->ThisTask->tc_Node.ln_Type != NT_PROCESS)
  39.     return(0);
  40.     if ((cli = BTOC(((Process *)SysBase->ThisTask)->pr_CLI, CLI)) == NULL)
  41.     return(0);
  42.  
  43.     ll = BTOC(cli->cli_CommandDir, LockList);
  44.  
  45.     while (ll) {
  46.     if (ll->PathLock) {
  47.         long oldLock = CurrentDir(ll->PathLock);
  48.         long lock;
  49.  
  50.         if (lock = Lock(cmd, SHARED_LOCK)) {
  51.         CurrentDir(oldLock);
  52.         return(lock);
  53.         }
  54.         CurrentDir(oldLock);
  55.     }
  56.     ll = BTOC(ll->NextPath, LockList);
  57.     }
  58.     return(0);
  59. }
  60.  
  61.  
  62.